package dao

import (
	"douhu_backend/internal/controller/common"
	authModel "douhu_backend/internal/model/auth"
	model "douhu_backend/internal/model/douyin"
	"time"
)

type HomepageDAO interface {
	// Profile operations
	CreateProfile(profile *model.Profile) error
	GetProfileByID(id string) (*model.Profile, error)
	GetProfiles(pagination *common.Pagination) (*common.PaginationResult, error)
	UpdateProfile(id string, profile *model.Profile) error
	DeleteProfile(id string) error

	// User operations
	CreateUser(user *model.User) error
	GetUserByProfileID(profileID string) (*model.User, error)
	UpdateUser(profileID string, user *model.User) error

	// Video operations
	CreateVideo(video *model.Video) error
	GetVideosByProfileID(profileID string, pagination *common.Pagination) (*common.PaginationResult, error)
	GetVideoByID(id string) (*model.Video, error)
	UpdateVideo(id string, video *model.Video) error
	DeleteVideo(id string) error
	GetVideos(pagination *common.Pagination) (*common.PaginationResult, error)
	GetVideosWithFilter(filter map[string]interface{}, pagination *common.Pagination, sortBy, sortOrder string) (*common.PaginationResult, error)
	BatchUpdateVideoStatus(videoIDs []string, status string) error
	BatchDeleteVideos(videoIDs []string) error
	GetVideoStats(filter map[string]interface{}) (*model.VideoStats, error)

	// Download operations
	CreateDownload(download *model.Download) error
	GetDownloadsByVideoID(videoID string) ([]*model.Download, error)
	UpdateDownload(id string, download *model.Download) error

	// Stats operations
	GetStats() (*model.Stats, error)
}

// AuthDAO 认证相关DAO接口
type AuthDAO interface {
	// User operations
	CreateUser(user *authModel.User) error
	GetUserByID(id uint64) (*authModel.User, error)
	GetUserByPhone(phone string) (*authModel.User, error)
	GetUserByUsername(username string) (*authModel.User, error)
	GetUserByWechatOpenID(openID string) (*authModel.User, error)
	GetUserByDouyinUID(uid string) (*authModel.User, error)
	UpdateUser(user *authModel.User) error
	UpdateUserProfile(userID uint64, updateData map[string]interface{}) error
	UpdateUserLastLogin(userID uint64, ip string, loginTime time.Time) error
	UpdateUserRefreshToken(userID uint64, refreshToken string, expiresAt time.Time) error
	ValidateRefreshToken(userID uint64, refreshToken string) (bool, error)

	// SMS code operations
	CreateSMSCode(smsCode *authModel.SMSCode) error
	GetValidSMSCode(phone string, codeType int) (*authModel.SMSCode, error)
	MarkSMSCodeUsed(id uint64, usedTime time.Time) error
	CleanExpiredSMSCodes() error
	GetSMSCodeSendCount(phone string, duration time.Duration) (int64, error)

	// Login attempt operations
	CreateLoginAttempt(attempt *authModel.LoginAttempt) error
	GetLoginAttempts(phone string, duration time.Duration) ([]*authModel.LoginAttempt, error)
	GetFailedLoginCount(phone string, duration time.Duration) (int64, error)

	// Login limit operations
	CreateOrUpdateLoginLimit(limit *authModel.LoginLimit) error
	GetLoginLimit(phone string) (*authModel.LoginLimit, error)
	ClearLoginLimit(phone string) error
	CleanExpiredLoginLimits() error

	// Helper methods
	IsRecordNotFound(err error) bool
}
